import Taro,{useState} from "@tarojs/taro";
import { View,Button } from "@tarojs/components";

function Axios(){
    const [list,setList] =useState(Array())
    const getAxios = ()=>{
        Taro.request({
            url:'https://apiblog.jspang.com/default/getArticleList'
        }).then(res=>{
            console.log('res: ', res);
            
        })
    }
    const getAxios2 =async ()=>{
   const res2 =   await  Taro.request({
       url:'https://apiblog.jspang.com/default/getArticleList'
    })
    console.log('res2: ', res2.data.list);
    setList(res2.data.list)
    }
    return(
        <View>
            第三个页面:获取axios请求
            <View>
                <Button
                onClick={getAxios}
                >
                    获取异步数据
                </Button>
                <Button
                onClick={getAxios2}
                >
                    获取异步数据2
                </Button>
               {
                   list.map((v,i)=>{
                       return <View key={i}>
                    {v.title}
                       </View>
                   })
               }
            </View>
        </View>
    )
}
export default Axios